﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace JEdwonTune.Lib.Jskit {
    public class Ctrls {
        public static void BindDirFile2Tree(String path, TreeNodeCollection tnc) {
            String[] dirs = Directory.GetDirectories(path);
            String[] files1 = Directory.GetFiles(path, "*.js");
            TreeNode f;
            for (int i = 0; i < files1.Length; i++) {
                f = new TreeNode(SortName(files1[i]));
                f.Tag = files1[i];
                tnc.Add(f);
            }
            for (int i = 0; i < dirs.Length; i++) {
                TreeNode newTn = new TreeNode(SortName(dirs[i]));
                newTn.Tag = dirs[i];
                tnc.Insert(0, newTn);
                BindDirFile2Tree(dirs[i], newTn.Nodes);
            }
        }
        public static String SortName(String filePath) {
            return filePath.Substring(filePath.LastIndexOf("\\")+1);
        }
    }
}
